package com.ymatou.query.trading.api.testcase;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.query.trading.api.parameter.GetOrderListByProductIdBean;
import com.ymatou.query.trading.api.service.GetOrderListByProductIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 根据商品ID获取对应订单信息 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetOrderListByProductId {

	private static GetOrderListByProductIdBean getorderlistbyproductidbean;
	private static GetOrderListByProductIdCall getorderlistbyproductidcall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据商品ID获取对应订单信息");
	}

	@Before
	public void caseUp() {

		getorderlistbyproductidbean = new GetOrderListByProductIdBean();
		getorderlistbyproductidcall = new GetOrderListByProductIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getorderlistbyproductidcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrderListByProductId_001() {
		Logger.start(true,"根据商品ID获取对应订单信息成功");
		try {
			// 创建订单
			// 创建订单
			PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
			int userId =placeOrderResp.getUserId();         
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
	
			
			String productId = "";

			// 参数
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-2100);
			getorderlistbyproductidbean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(730);
			getorderlistbyproductidbean.setEndTime(EndTime);
			getorderlistbyproductidbean.setProductId(productId);
			// 发送请求
			getorderlistbyproductidcall.setData(getorderlistbyproductidbean);
			getorderlistbyproductidcall.callService();
			Logger.comment("getorderlistbyproductidcall send:" + getorderlistbyproductidcall.getEntityString());
			Logger.comment("getorderlistbyproductidcall response:" + getorderlistbyproductidcall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, getorderlistbyproductidcall.getCode(), "验证Code");
			// Logger.verifyEquals(ErrorCode.SUCCESSMSG2,
			// getorderlistbyproductidcall.getMsg(), "验证Msg");
			Logger.verifyEquals(true, getorderlistbyproductidcall.getOrderInfoList().size() > 0, "验证查询结果长度");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrderListByProductId_002() {
		Logger.start(true,"商品ID不存在，查询不到结果");
		try {
			// 参数
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-100);
			getorderlistbyproductidbean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getorderlistbyproductidbean.setEndTime(EndTime);
			String productid = "7aa433ed-bf8a-4e7e-aee5-1f0d4eba45cb" + "s";
			getorderlistbyproductidbean.setProductId(productid);
			// 发送请求
			getorderlistbyproductidcall.setData(getorderlistbyproductidbean);
			getorderlistbyproductidcall.callService();
			// Logger.debug(getorderlistbyproductidcall.getReturnData());
			Logger.comment("getorderlistbyproductidcall send:" + getorderlistbyproductidcall.getEntityString());
			Logger.comment("getorderlistbyproductidcall response:" + getorderlistbyproductidcall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, getorderlistbyproductidcall.getCode(), "验证Code");
			// Logger.verifyEquals(ErrorCode.SUCCESSMSG,
			// getorderlistbyproductidcall.getMsg(), "验证Msg");
			Logger.verifyEquals(0, getorderlistbyproductidcall.getOrderInfoList().size(), "验证查询结果长度");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}